package com.qire.manhua.controller;

import android.view.View;

import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;
import com.qire.common.basic.ObjectUtil;
import com.qire.common.constant.Navigation;
import com.qire.common.support.base.EventController;
import com.qire.common.widget.adapter.auto.AutoVariable;
import com.qire.manhua.BR;
import com.qire.manhua.dialog.TeensRestrictReadDialog;
import com.qire.manhua.model.entity.HomeModuleEntity.HomeModuleItemEntity;
import com.qire.manhua.model.viewModel.impl.RecommendModuleViewModel;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.LifecycleOwner;

public abstract class RecommendModuleController<O extends LifecycleOwner> extends EventController<O> implements AutoVariable {

    public RecommendModuleController(@NonNull O lifecycleOwner) {
        super(lifecycleOwner);
    }

    @Override
    public void bindVariable(ViewDataBinding viewBind) {
        viewBind.setVariable(BR.recommendModuleController, this);
    }

    public void moduleRecordItemOnClick(View view) {
        HomeModuleItemEntity moduleItemEntity = ObjectUtil.as(view.getTag(), HomeModuleItemEntity.class);
        if(ObjectUtil.nonNull(moduleItemEntity)) {
            if(moduleItemEntity.isTeensVisible()) {
                AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.ComicReaderPage)
                        .withData("comicBookEntity", moduleItemEntity.toComicBookEntity())
                        .navigation();
            } else {
                new TeensRestrictReadDialog(view.getContext()).show();
            }
        }
    }

    public void moduleItemOnClick(View view) {
        HomeModuleItemEntity moduleItemEntity = ObjectUtil.as(view.getTag(), HomeModuleItemEntity.class);
        if(ObjectUtil.nonNull(moduleItemEntity)) {
            if(moduleItemEntity.isTeensVisible()) {
                AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.ComicQuickReadPage)
                        .withData("comicBookEntity", moduleItemEntity.toComicBookEntity())
                        .navigation();
            } else {
                new TeensRestrictReadDialog(view.getContext()).show();
            }
        }
    }

    public void moduleBottomMenuMoreOnClick(View view) {
        RecommendModuleViewModel moduleViewModel = (RecommendModuleViewModel) view.getTag();
        if(moduleViewModel.moduleId() == 998) {
//            AntsRouter.ROUTER.<RoomCard>buildCard(Navigation.Fragment.BookshelfFragment)
//                    .to(owner);
            return;
        }
        // 打开“更多”对应的列表
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.RecommendMorePage)
                .withData("moduleId", moduleViewModel.moduleId())
                .withData("moduleTitle", moduleViewModel.moduleTitle())
                .navigation();
    }

    public void moduleBottomMenuRefreshOnClick(View view) {
        RecommendModuleViewModel moduleViewModel = (RecommendModuleViewModel) view.getTag();
        moduleViewModel.nextBatch();
    }
}
